<?php

class Ht_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
	private $_acl = null;
 
	public function __construct(Zend_Acl $acl) {
		$this->_acl = $acl;
	}
	 
	public function preDispatch(Zend_Controller_Request_Abstract $request) {
		    
	    if(Zend_Auth::getInstance()->hasIdentity()) {
	    	$user = Zend_Auth::getInstance()->getIdentity();
	    	$role =  $user->rid;
	    }
		else {
			$role = 'guest';
		}
	    //Controller = Ressource
	    $resource = $request->getControllerName();
	    $privilege = $request->getActionName();
	 
	    if(!$this->_acl->isAllowed($role,  $resource, $privilege)) {
	    	//User weiterleiten auf notallowed-Meldung
	    	$request->setControllerName('index')
	              	->setActionName('notallowed');
		}
	}
};
?>